package com.example.ui_view.resource_use;

import androidx.appcompat.app.AppCompatActivity;

import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.util.Log;
import android.view.ContextMenu;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.example.ui_view.R;

public class resourceActivity extends AppCompatActivity {
    private TextView tv_resource;
    LinearLayout ll_layout;
    private ImageView imageView,imageView2;
    private Animation animation;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_resource);
        tv_resource = findViewById(R.id.tv_resource);
        ll_layout = findViewById(R.id.ll_layout);
        imageView = findViewById(R.id.imageView);
        imageView2 = findViewById(R.id.imageView2);
        registerForContextMenu(tv_resource);
        animation = AnimationUtils.loadAnimation(this,R.anim.animations);

        String[] str = getResources().getStringArray(R.array.str_array);
        String text = "";
        for (String item: str ) {
            text += "   " + item;
        }
        tv_resource.setText(text);
        tv_resource.setTextColor(getResources().getColor(R.color.colorPrimary) );
        LayoutInflater inflater = LayoutInflater.from(this);
        inflater.inflate(R.layout.resource_layout,ll_layout);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {

        menu.add(1,1,0,"option1");
        menu.add(1,2,0,"option2");
        menu.add(1,3,0,"option3");
        menu.add(1,4,0,"option4");
        return super.onCreateOptionsMenu(menu);

    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        return super.onOptionsItemSelected(item);
    }

    @Override
    public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
        MenuInflater inflater = new MenuInflater(this);
        inflater.inflate(R.menu.menus,menu);
    }

    @Override
    public boolean onContextItemSelected(MenuItem item) {

        switch (item.getItemId()){
            case R.id.item1:
                Toast.makeText(this, ""+item.getTitle(), Toast.LENGTH_SHORT).show();
                break;
            case R.id.item2:
                Toast.makeText(this, ""+item.getTitle(), Toast.LENGTH_SHORT).show();
                break;
            case R.id.item3:
                Toast.makeText(this, ""+item.getTitle(), Toast.LENGTH_SHORT).show();
                break;
            case R.id.item4:
                Toast.makeText(this, ""+item.getTitle(), Toast.LENGTH_SHORT).show();
                break;
            default:
                break;
       }
        return true;
    }

    public void start(View view) {
        imageView.startAnimation(animation);
    }

    public void startFrame(View view) {
        imageView2.setImageResource(R.drawable.frame_animation);
        AnimationDrawable drawable1 = (AnimationDrawable) imageView2.getDrawable();
        drawable1.start();
    }
}
    
